package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbGarbageMail;
import com.ruoyi.system.service.ITbGarbageMailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 反垃圾邮件Controller
 * 
 * @author Ranvekin
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/mail")
public class TbGarbageMailController extends BaseController
{
    @Autowired
    private ITbGarbageMailService tbGarbageMailService;

    /**
     * 查询反垃圾邮件列表
     */
    @PreAuthorize("@ss.hasPermi('system:mail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbGarbageMail tbGarbageMail)
    {
        startPage();
        List<TbGarbageMail> list = tbGarbageMailService.selectTbGarbageMailList(tbGarbageMail);
        return getDataTable(list);
    }

    /**
     * 导出反垃圾邮件列表
     */
    @PreAuthorize("@ss.hasPermi('system:mail:export')")
    @Log(title = "反垃圾邮件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGarbageMail tbGarbageMail)
    {
        List<TbGarbageMail> list = tbGarbageMailService.selectTbGarbageMailList(tbGarbageMail);
        ExcelUtil<TbGarbageMail> util = new ExcelUtil<TbGarbageMail>(TbGarbageMail.class);
        util.exportExcel(response, list, "反垃圾邮件数据");
    }

    /**
     * 获取反垃圾邮件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mail:query')")
    @GetMapping(value = "/{spamId}")
    public AjaxResult getInfo(@PathVariable("spamId") String spamId)
    {
        return success(tbGarbageMailService.selectTbGarbageMailBySpamId(spamId));
    }

    /**
     * 新增反垃圾邮件
     */
    @PreAuthorize("@ss.hasPermi('system:mail:add')")
    @Log(title = "反垃圾邮件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGarbageMail tbGarbageMail)
    {
        return toAjax(tbGarbageMailService.insertTbGarbageMail(tbGarbageMail));
    }

    /**
     * 修改反垃圾邮件
     */
    @PreAuthorize("@ss.hasPermi('system:mail:edit')")
    @Log(title = "反垃圾邮件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGarbageMail tbGarbageMail)
    {
        return toAjax(tbGarbageMailService.updateTbGarbageMail(tbGarbageMail));
    }

    /**
     * 删除反垃圾邮件
     */
    @PreAuthorize("@ss.hasPermi('system:mail:remove')")
    @Log(title = "反垃圾邮件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{spamIds}")
    public AjaxResult remove(@PathVariable String[] spamIds)
    {
        return toAjax(tbGarbageMailService.deleteTbGarbageMailBySpamIds(spamIds));
    }
}
